home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / lh211src.zip / DOSIO.C < prev    next >
C/C++ Source or Header  |  1991-01-18  |  3KB  |  128 lines

  1. /***********************************************************
  2.     dosio.c -- MS-DOS dependent I/O
  3. ***********************************************************/
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <dos.h>
  8. #include "lh.h"
  9.  
  10. time_t getfiletime(FILE *f)
  11. {
  12.     union stamp stamp;
  13.  
  14.     _dos_getftime(fileno(f), (unsigned *)&(stamp.t.date), 
  15.                              (unsigned *)&(stamp.t.time));
  16.     return dos2unix(&stamp.s);
  17. }
  18.  
  19. int setfiletime(FILE *f, time_t utc)
  20. {
  21.     union stamp *stamp;
  22.  
  23.     stamp = (union stamp *)unix2dos(utc);
  24.     fflush(f);
  25.     return _dos_setftime(fileno(f), stamp -> t.date, stamp -> t.time);
  26. }
  27.  
  28. static char breakval;
  29.  
  30. static char breakctrl(char al, char dl)
  31. {
  32.     union REGS reg;
  33.  
  34.     reg.h.ah = 0x33;
  35.     reg.h.al = al;
  36.     reg.h.dl = dl;
  37.     intdos(®, ®);
  38.     return reg.h.dl;
  39. }
  40.  
  41. void break_get_on(void)
  42. {
  43.     breakval = breakctrl(0, 0);
  44.     breakctrl(1, 1);
  45. }
  46.  
  47. void break_off(void)
  48. {
  49.     breakctrl(1, 0);
  50. }
  51.  
  52. void break_set(void)
  53. {
  54.     breakctrl(1, breakval);
  55. }
  56.  
  57. #if 0
  58. #if 1
  59. int getfileattr(char *path)
  60. {
  61.     union REGS reg;
  62.     struct SREGS sreg;
  63.  
  64.     segread(&sreg);
  65.     reg.x.ax = 0x4300;
  66.     reg.x.dx = FP_OFF(path);
  67.     sreg.ds = FP_SEG(path);
  68.     intdosx(®, ®, &sreg);
  69.     return reg.x.cflag ? -1 : reg.x.cx;
  70. }
  71.  
  72. int setfileattr(char *path, int attr)
  73. {
  74.     union REGS reg;
  75.     struct SREGS sreg;
  76.  
  77.     segread(&sreg);
  78.     reg.x.ax = 0x4301;
  79.     reg.x.cx = attr;
  80.     reg.x.dx = FP_OFF(path);
  81.     sreg.ds = FP_SEG(path);
  82.     intdosx(®, ®, &sreg);
  83.     return reg.x.cflag ? -1 : reg.x.cx;
  84. }
  85.  
  86. #else
  87. int getfileattr(char *path)
  88. {
  89.     int i;
  90.  
  91.     return _chmod(path, 0);
  92. }
  93.  
  94. int setfileattr(char *path, int attr)
  95. {
  96.     return _chmod(path, 1, attr);
  97. }
  98. #endif
  99. #endif
  100.  
  101. static char physicaldrive(char *filename)
  102. {
  103.     union REGS regs;
  104.     char physical[80];
  105.  
  106.     strcpy(physical, filename);
  107.     regs.x.si = (unsigned)filename;
  108.     regs.x.di = (unsigned)physical;
  109.     regs.h.ah = 0x60;
  110.     intdos(®s, ®s);
  111.     if (physical[1] != ':') return 0;
  112.     return *physical - 'A' + 1;
  113. }
  114.  
  115. long diskspace(char *filename)
  116. {
  117.     struct diskfree_t dtable;
  118.     struct find_t srchbuf;
  119.     long cluster, freespace;
  120.  
  121.     if (_dos_findfirst(filename, 0x07, &srchbuf)) srchbuf.size = 0;
  122.     _dos_getdiskfree(physicaldrive(filename), &dtable);
  123.     cluster = (long)dtable.bytes_per_sector * (long)dtable.sectors_per_cluster;
  124.     freespace = (long)dtable.avail_clusters * cluster;
  125.     freespace += (srchbuf.size + cluster - 1) / cluster * cluster;
  126.     return freespace;
  127. }
  128.